﻿using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MachineBuildingSystem
{
    public partial class HaveNewFormulaInfo : XtraForm
    {
        public HaveNewFormulaInfo()
        {
            InitializeComponent();
        }

        private List<FormulasStatusInfo> m_FormulasStatusInfoList = new List<FormulasStatusInfo>();
        public List<FormulasStatusInfo> FormulasStatusInfoList
        {
            get { return m_FormulasStatusInfoList; }
            set { m_FormulasStatusInfoList = value; }
        }

        private void HaveNewFormulaInfo_Load(object sender, EventArgs e)
        {
            if (m_FormulasStatusInfoList != null)
            {
                int width = 0;
                int height = 0;
                foreach (FormulasStatusInfo info in m_FormulasStatusInfoList)
                {
                    int tempWidth = width;
                    HyperLinkEdit hypeLink = CreateHyperLinkEdit(info.orderCode, info.saleId);
                    width += hypeLink.Width;
                    if (width > this.pnlInfo.Width)
                    {
                        width = 0;
                        tempWidth = width;
                        height += hypeLink.Height;
                    }
                    hypeLink.Location = new Point(tempWidth, height);
                    pnlInfo.Controls.Add(hypeLink);
                }
            }
        }

        private HyperLinkEdit CreateHyperLinkEdit(string orderCode, long saleId)
        {
            HyperLinkEdit hypeLink = new HyperLinkEdit();
            hypeLink.Properties.Appearance.BackColor = System.Drawing.Color.Transparent;
            hypeLink.Properties.Appearance.Options.UseBackColor = true;
            hypeLink.Properties.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
            hypeLink.Size = new System.Drawing.Size(orderCode.Length * 10, 18);
            hypeLink.Text = orderCode + "(" + saleId + ")";
            hypeLink.OpenLink += hypeLink_OpenLink;
            return hypeLink;
        }

        void hypeLink_OpenLink(object sender, DevExpress.XtraEditors.Controls.OpenLinkEventArgs e)
        {
            try
            {
                string[] strArr = e.EditValue.ToString().Split('(');
                long saleId = Convert.ToInt64(strArr[1].TrimEnd(')'));
                FormulasStatusEventArgs args = new FormulasStatusEventArgs(saleId);
                if (OnSaleFormulasByStatus_Event != null)
                {
                    this.Close();
                    OnSaleFormulasByStatus_Event(this, args);
                }
            }
            catch (Exception ex)
            {
                LogHelper.error("打开订单链接异常：" + ex.ToString());
            }

        }
        public event EventHandler<FormulasStatusEventArgs> OnSaleFormulasByStatus_Event;
    }
}
